package com.zlt.bkparking.controller.parking;

import com.zlt.bkparking.dto.CarAddressDTO;
import com.zlt.bkparking.service.CarAddressService;
import com.zlt.bkparking.vo.ParkingLotVO;
import com.zlt.bkparking.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("carAddress")
@Api(value = "Swagger调试",tags = "Swagger 调试")
@Slf4j
public class CarAddressController {

    @Autowired
    private CarAddressService carAddressService;

    @ApiOperation("停车场管理员查询自己管理的车位信息")
    @GetMapping("selectParkingLotBybuId")
    public Result selectParkingLotBybuId() {
        try {
            List<ParkingLotVO> parkingLotVOS = carAddressService.selectParkingLotBybuId();
            return parkingLotVOS!=null ? Result.ok("成功",parkingLotVOS):Result.error("失败");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("失败");
        }
    }

    @ApiOperation("停车场管理员修改或添加车位信息的接口")
    @PostMapping("updateCarAddress")
    public Result updateCarAddress( @ApiParam  CarAddressDTO carAddressDTO) {
        log.debug("获取所有停车场订单的数据{}", carAddressDTO);
        boolean isSuccess= false;
        try {
            isSuccess = carAddressService.updateCarAddress(carAddressDTO);
            return isSuccess ? Result.ok("修改成功"):Result.error("修改失败");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("修改失败");
        }
    }




}
